package com.zhongkun.datahome.core.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongkun.datahome.common.core.domain.entity.Tenant;
import com.zhongkun.datahome.core.mapper.TenantMapper;
import org.springframework.stereotype.Repository;

import java.util.Objects;

/**
 * @Author: lifengsheng
 * @Date: 2025/5/6 12:13
 * @Desc
 */
@Repository
public class TenantRepository extends ServiceImpl<TenantMapper, Tenant> {
    public Tenant getByName(String tenantName) {
        return this.getOne(new LambdaQueryWrapper<Tenant>().eq(Tenant::getTenantName, tenantName), false);
    }

    public String getName(Long tenantId) {
        Tenant tenant = this.getOne(new LambdaQueryWrapper<Tenant>().eq(Tenant::getId, tenantId), false);
        return Objects.isNull(tenant) ? null : tenant.getTenantName();
    }
}
